home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_10.lha
/
7_10
/
qh_get.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
54 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <process.h>
include <debug.h> /* DELETE */
/ Return an object from the head of the queue.
/ If necessary, pause and loop
/ until one becomes available.
rocess_object *queue_head::get()
if (debug) /*DELETE*/ cerr << "queue_head" << this << "::get()\n";
register process_queue *q = qh_queue;
while (q->q_count == 0)
switch (qh_mode)
{
case Q_WMODE:
this_process()->pause(this);
break;
case Q_EMODE:
error("queue_head::get(): empty queue");
break;
case Q_ZMODE:
if (debug) /*DELETE*/ cerr << "<<<< queue_head" << this << "::get() <- 0\n";
return 0;
}
process_object *last = q->q_last;
process_object *first = last->po_next;
// the queue was full
int wasfull = (q->q_count-- == q->q_max);
// is the queue now empty
if (q->q_count == 0)
first->po_next = q->q_last = 0;
// does the queue still have some objects on it
else
{
last->po_next = first->po_next;
first->po_next = 0;
}
if (wasfull && q->q_tail)
q->q_tail->alert();
if (debug) /*DELETE*/ cerr << "<<<< queue_head" << this << "::get()\n";
return first;